package cn.zxy.config;

import cn.zxy.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Value("${token.key}")
    private String tokenKey;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        TokenInterceptor tokenInterceptor = new TokenInterceptor(tokenKey);
//        链式调用
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/api/user/login","/api/user/register")//白名单
                .order(1);//数字越小，越先执行
    }
}
